package com.xgd.phylw.controller;

import com.xgd.phylw.bean.Movie;
import com.xgd.phylw.bean.Schedule;
import com.xgd.phylw.bean.Seat;
import com.xgd.phylw.service.MovieService;
import com.xgd.phylw.service.ScheduleService;
import com.xgd.phylw.service.SeatService;
import com.xgd.phylw.service.TopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;
//主页头部页面跳转控制
@Controller
public class FrontPageController {
    @Autowired
    private TopService topService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private SeatService seatService;
    @Autowired
    private MovieService movieService;
    //cinema。jsp页面数据显示以及跳转
    @RequestMapping("Cinema")
    public String PageChangeToCinema(Model model){
        List<Schedule> schedules = topService.SelectAllSchedule();
        model.addAttribute("schedules",schedules);
        return "cinema";
    }
    //movie.jsp 页面数据显示以及跳转
    @RequestMapping("Movie")
    public String PageChangeToMovie(Model model){
        return "movie";
    }
    //myMess.jsp 页面数据显示以及跳转
    @RequestMapping("MyMess")
    public String PageChangeToMyMess(Model model){
        return "myMess";
    }
    //message.jsp 页面数据显示以及跳转
    @RequestMapping("Message")
    public String PageChangeToMessage(Model model){
        return "message";
    }
    @RequestMapping("Seat")
    public String PageChangeToSeat(Integer scheduleId, Model model){
        System.out.println(scheduleId);
        Schedule schedule = scheduleService.selectByPrimaryKey(scheduleId);
        List<Seat> seatList = seatService.selectByScheduleId(schedule.getScheduleId());
        model.addAttribute("schedule",schedule);
        Movie movie = movieService.selectByPrimaryKey(schedule.getMovieId());
        model.addAttribute("movie",movie);
        Integer seatTotal = seatService.selectSeatsByScheduleId(scheduleId);
        model.addAttribute("seatTotal",seatTotal);
        List<Integer> row = new ArrayList<Integer>();
        List<Integer> column = new ArrayList<Integer>();
        if(seatList.size()>0){
            for (Seat seat : seatList) {
                row.add(seat.getSetRow());
                column.add(seat.getSetColumn());
            }
        }
        model.addAttribute("row",row);
        model.addAttribute("column",column);
        return "seat";
    }
    @RequestMapping("CinemaMovie")
    public String PageChangeToCinemaMovie(Model model){
        return "cinema-movie";
    }
}
